export function formatDate(dateString: string): string {
  const now: Date = new Date()
  const pastDate: Date = new Date(dateString)
  const diffInSeconds: number = Math.floor((now.getTime() - pastDate.getTime()) / 1000)

  if (diffInSeconds < 60) {
    return `${diffInSeconds}秒前`
  } else if (diffInSeconds < 3600) {
    const minutes: number = Math.floor(diffInSeconds / 60)
    return `${minutes}分钟前`
  } else if (diffInSeconds < 86400) {
    const hours: number = Math.floor(diffInSeconds / 3600)
    return `${hours}小时前`
  } else {
    const days: number = Math.floor(diffInSeconds / 86400)
    const options: Intl.DateTimeFormatOptions = {
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
    }
    return pastDate.toLocaleDateString('zh-CN', options) // 返回年月日格式
  }
}
